package org.dut.ioc.Controller;

import jakarta.annotation.Resource;
import org.dut.ioc.Service.UserService;
import org.dut.ioc.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {
    //属性注入
    @Autowired
    private UserService userService;
//   @Qualifier("u1")  //指定要注入的bean,搭配Autowired使用
//    @Autowired

    //JavaEE原生注解
    @Resource(name = "u1")
    private User user;

    //构造方法注入,默认注入无参构造函数
//    public UserController(){
//
//    }
//    @Autowired
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }


    //setter方法注入
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }


    public void hello() {
        System.out.println("hello UserController");
        userService.sayHello();
        System.out.println(user);
    }


}
